home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 1.9 KB | 86 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SmrtPtr.h
- // Release Version: $ ODF 2 $
- //
- // Author: Mark Lanett
- //
- // Copyright (c) 1995 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- // Template smart pointer (envelope) class
- //
- //========================================================================================
-
- #ifndef _ODF_Smart_Pointers_
- #define _ODF_Smart_Pointers_
-
- //-----------------------------------------------------------------------------
- // TPointer
- // This is an envelope class, more robust than TempObj (OD Utilities)
- // TempObj doesn't support operator=
- //-----------------------------------------------------------------------------
-
- template <class T>
- class TPointer {
- public:
- FW_DECLARE_AUTO (TPointer)
- inline TPointer ();
- inline TPointer (T* object);
- inline ~TPointer ();
- inline TPointer<T>& operator= (T* object);
- inline void Assign (T* object);
- inline T* Release ();
- private:
- T* fObject;
- private:
- TPointer (const TPointer<T>& other) {}
- TPointer<T>& operator= (const TPointer<T>& other) {return *this;}
- };
-
- //-----------------------------------------------------------------------------
- // TPointer Inlines
- //-----------------------------------------------------------------------------
-
- template <class T> inline
- TPointer<T>::TPointer ()
- : fObject (kODNULL)
- {
- }
-
- template <class T> inline
- TPointer<T>::TPointer (T* object)
- : fObject (object)
- {
- }
-
- template <class T> inline
- TPointer<T>::~TPointer ()
- {
- Assign (kODNULL);
- }
-
- template <class T> inline
- TPointer<T>& TPointer<T>::operator= (T* object)
- {
- Assign (object);
- return *this;
- }
-
- template <class T> inline
- void TPointer<T>::Assign (T* object)
- {
- delete fObject;
- fObject = object;
- }
-
- template <class T> inline
- T* TPointer<T>::Release ()
- {
- T* temporary = fObject;
- fObject = kODNULL;
- return temporary;
- }
-
- #endif // _ODF_Smart_Pointers_
-
-